package com.bruce.pattern.creational.singleton;

import lombok.extern.slf4j.Slf4j;

/**
 * 线程范围内 单例
 * <p>
 * Created by bruce on 2018/11/3 14:14
 */
@Slf4j
public class ThreadLocalInstance {

    private static final ThreadLocal<ThreadLocalInstance> threadLocal = ThreadLocal.withInitial(ThreadLocalInstance::new);

    // private static final ThreadLocal<ThreadLocalInstance> threadLocal = new ThreadLocal<ThreadLocalInstance>(){
    //     @Override
    //     protected ThreadLocalInstance initialValue() {
    //         //某个线程初始值
    //         return new ThreadLocalInstance();
    //     }
    // };

    private ThreadLocalInstance(){

    }

    public static ThreadLocalInstance getInstance(){
       return threadLocal.get();
    }

    public void sayHello(){
        log.info(Thread.currentThread().getName());
    }





}
